<?php
/**
Version 0.1
SEMF - Web Desiging Framework for Sport Event Managment
Copyright (C) 2006, SEMF Developers

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
$action = $_GET["action"];

header('Content-Type: text/xml');
header('Cache-control: no-cache');

include_once("util/dirutils.php");

if( $action == "new_file")
{
	$file_name = $_GET["newPath"];
	$file = fopen( $file_name, "w+");
	$content = "";
	fwrite($file, $content, strlen($content));
	fclose($file);
	
	echo "<msg>";
	echo "successfull";
	echo "</msg>";
}
elseif( $action == "new_dir")
{
	$dir_name = $_GET["newPath"];
	
	if(!is_dir($dir_name))
	{
		mkdir($dir_name);
		echo "<msg>";
		echo "successfull";
		echo "</msg>";
	}
	else
	{
		echo "<msg>";
		echo "Directory already there..";
		echo "</msg>";
	}
}
elseif( $action == "copy" || $action == "move")
{
	$source = $_GET["source"];
	$dest = $_GET["dest"];
	$justDest = $_GET["justDest"];
	
	//$source = str_replace(" ", "\ ", $source);
	//$dest = str_replace(" ", "\ ", $dest);
	
	if(!is_dir($source) && !is_file($source))
	{
		echo "<msg>";
		echo "Source doesn't exist";
		echo "</msg>";
	}
	else if(!is_dir($dest))
	{
		echo "<msg>";
		echo "Destination dir doesn't exist..";
		echo "</msg>";
	}
	else
	{
		if( is_dir($source)) 
		{
			$source.= "/";
		}
		$dest.= "/";
		copy_dir($source, $dest, $justDest);
		echo $source."\n".$dest;
		if( $action == "move" )
		{
			if( is_dir($source) )
			{
				deldir($source);
			}
			else
			{
				unlink($source);
			}
		}
		echo "<msg>";
		echo "Deleted Successfully..";
		echo "</msg>";
	}
}
elseif( $action == "delete")
{
	$dest = $_GET["dest"];
	//$dest = str_replace(" ", "\ ", $dest);
	if( is_dir($dest) )
	{
		deldir($dest);
	}
	else
	{
		unlink($dest);
	}
	echo "<msg>";
	echo "successfull";
	echo "</msg>";
}


?>